package com.yeheng;

/**
 * @Classname Singleton
 * @Description :
 * @Date 2021/3/3 19:02
 * @Created by Yeheng
 */
public class Singleton {
    private volatile static Singleton singleton;
    //防止指令重排，保持singleton可见性
    //唯一构造私有
    private Singleton(){

    }

    public static Singleton getInstance(){
        //防止其他线程进入等锁队列
        if (singleton ==null){
            synchronized (Singleton.class){
                if (singleton == null){
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }
}
